package com.wyy.springbootgraphql.resolver;

import com.wyy.springbootgraphql.beans.Comments;
import com.wyy.springbootgraphql.beans.Post;
import graphql.kickstart.tools.GraphQLQueryResolver;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class PostQueryService implements GraphQLQueryResolver {

    public Post getPostById(String id){
        if("1".equals(id)){
            Post post = new Post("1","Hello,Graphql","Graphql初体验");
            Comments c = new Comments("001", "太好看了");
            ArrayList<Comments> list = new ArrayList<>();
            list.add(c);
            list.add(c);
            list.add(c);
            list.add(c);
            post.setComments(list);
            return post;
        }else{
            return null;
        }
    }

    // 查看列表
    public List<Post> showPosts(){
        Post post1 = new Post("001", "123", "123414j;als");
        Post post2 = new Post("002", "121233", "12341234j;als");
        Comments comments = new Comments("123", "32rjflk");
        ArrayList<Comments> cList = new ArrayList<>();
        cList.add(comments);
        cList.add(comments);
        cList.add(comments);
        post1.setComments(cList);
        post2.setComments(cList);

        ArrayList<Post> posts = new ArrayList<>();
        posts.add(post1);
        posts.add(post2);
        return posts;
    }

    // 查看某条帖子的评论：
    public List<Comments> getPostByIdShowComment(String id){
        if ("001".equals(id)){
            Comments comments = new Comments("asd", "32rjflk");
            ArrayList<Comments> cList = new ArrayList<>();
            cList.add(comments);
            cList.add(comments);
            cList.add(comments);
            return cList;
        } else
            return null;
    }
}
